<template>
	<view class="page" :style="'height:' + height + 'rpx'">
		<view class="noDataTip" v-if="result.length == 0">
			<view class="iconfont icon-wuanpai" style="color:#6B6B6B;margin-right: 25rpx;font-size: 45rpx;"></view>
			<view style="font-size: 45rpx;">暂无来访记录!</view>
		</view>
		<view v-else class="result">
			<view class="date_item" v-for="(item,index) in result" :key="index">
				<view class="top">
					{{item.date}}
				</view>
				<miTaPersonItem @toHimCourse="toHimCourse()" class="person_item"   v-for="(item1,index1) in item.esvoList" :key="index1" :person="item1" :lineHeight="false"></miTaPersonItem>
			</view>
		</view>

	</view>

</template>

<script>
	import miTaPersonItem from "../../components/miTaPersonItem/miTaPersonItem.vue"
	import toHimCourseMixin from "../../static/js/toHimCourse.js"
	export default {
		mixins: [toHimCourseMixin],
		onLoad(options) {
			//广告
			// if (wx.createRewardedVideoAd) {
			// 	this.rewardedVideoAd = wx.createRewardedVideoAd({
			// 		adUnitId: 'adunit-db19f55e90f0f2c3'
			// 	})
			// 	this.rewardedVideoAd.onLoad(() => {
			// 		// console.log('激励视频 广告加载成功')
			// 	})
			// 	this.rewardedVideoAd.onError((err) => {
			// 		// console.log('拉取失败', err)
			// 	})
			// 	this.rewardedVideoAd.onClose((res) => {
			// 		// console.log('激励视频 广告关闭');
			// 		if (res.isEnded) {
			// 			that.getVistorData();
			// 		} else {
			// 			uni.showToast({
			// 			    title: '未观看完广告',
			// 				icon: 'error',
			// 			    duration: 2000
			// 			});
			// 			uni.redirectTo({
			// 			    url: '../findHim/findHim'
			// 			});
						
			// 		}
					
			// 	})
			// }
			
		   let that = this;
		   this.header = getApp().globalData.header;		
			console.log(options.hasNewVistor)
			if (options.hasNewVistor == 'true') {
				this.hasNewVistor = true;
				that.getVistorData();
				// uni.showModal({
				// 	title: '提示',
				// 	content: '需要观看完广告，才可查看新来访者',
				// 	success: async function(res) {
				// 		if (res.confirm) {
				// 			that.rewardedVideoAd.show()
				// 				.catch(() => {
				// 					that.rewardedVideoAd.load()
				// 						.then(() => that.rewardedVideoAd.show())
				// 						.catch(err => {
				// 							// console.log('激励视频 广告显示失败')
				// 						})
				// 				})
				// 		} else if (res.cancel) {
				// 			// console.log('用户点击取消');
				// 		}
				// 	}
				// });
			} else {
				this.hasNewVistor = false;
				this.getVistorData()
			}			
			uni.getSystemInfo({
				success: function(res) {
					let pxToRpxScale = 750 / res.windowWidth;
					// console.log(res.windowHeight);

					that.height = res.windowHeight * pxToRpxScale;
					// console.log(that.height)
				}
			})			
		},
		data() {
			return {
				height: 0,
				header: {},
				result: [],
				rewardedVideoAd: null,
				hasNewVistor: false
			}
		},
		methods: {
			async getVistorData() {
				uni.showLoading({
					title: '加载中..',
					mask: true
				});
				let res = await getApp().UniRequest("/mita/authority/browsingHistory/other", "Get", "",
					this.header);
					console.log(res)
				if (res.code === 20000) {
					
					// console.log('来访记录',res)
					let data = res.data;
					this.result = data.stu.list;
					this.hasNewVistor = false;
					uni.hideLoading();
				}
				  
			},
			
			//有新访客
			 async isNewVistor() {
				let res = await getApp().UniRequest("/mita/authority/hasBrowsingHistory", "GET", "",
					this.header);
					if (res.success) {
						this.hasNewVistor = true;
					} else {
						this.hasNewVistor = false;
					}

					console.log('有访客',res)
			},
		},
		components: {
			miTaPersonItem
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		position: relative;
		padding: 20rpx;
		background-color: #f2f2f2;

		button {
			background-color: #fff;
			border: 0rpx;
			padding-right: 10rpx;
			padding-left: 10rpx;
		}
		
		.noDataTip {
			height: 150rpx;
			width: 650rpx;
			line-height: 50rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			position: absolute;
			top: 50%;
			margin-top: -150rpx;
			left: 50%;
			margin-left: -325rpx;
			font-size: 50rpx;
			color: #6B6B6B;
			// background-color: #fff;
			// box-shadow: 0.5rpx 0.5rpx 40rpx #DBDBDB;
			border-radius: 20rpx;
		}
		.result {
			height: 100%;
			width: 100%;

			
			// padding-top: ;
			.date_item {
				position: relative;
				margin: 0 auto;
				margin-top: 90rpx;
				width: 100%;
				// height: 400rpx;
				border-top-left-radius: 10rpx;
				border-top-right-radius: 10rpx;
				border-top: 3rpx solid #7D7D7D;
				background-color:  	#F7F7F7;
			&:first-child {
				margin-top: 40rpx;
			}
				.top {
					position: absolute;
					top: -30rpx;
					left: 20rpx;
					padding-left: 20rpx;
					padding-right: 20rpx;
					// width: 40%;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					font-size: 30rpx;
					background-color: #f2f2f2;
			
				}
			}
		}
	}
</style>
